package com.eascs.web.p2p.action;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.p2p.common.service.IDatadicService;
import com.eascs.p2p.common.vo.DatadicVO;
import com.eascs.p2p.common.vo.ModelResult;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.view.BaseRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.AjaxButton;
import com.eascs.site.view.button.Button;
import com.eascs.tag.MenuTag;
import com.eascs.web.p2p.common.BaseMasterViewController;

@Controller
@RequestMapping("/datadic")
public class DatadicController extends BaseMasterViewController {

	@Reference
	IDatadicService  datadicServic;

	@Override
	public void preHandle() {
		super.preHandle();
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "admin");
	}

	
	/**
	 * @Title: index
	 * @Description: 字典信息列表
	 * @author 张庆奇
	 * @param vo
	 * @return
	 * @return String
	 * @throws
	 * @date 2016年8月5日 下午3:50:52
	 */
	@RequestMapping(value = "/index")
	public String index(DatadicVO vo) {

		vo.setPageSize(10);
		ModelResult<PageResult<Object[]>> model = datadicServic.pageFindDatadic(vo);
		PageResult<Object[]> pageResult = new PageResult<Object[]>();
		if (model.isSuccess()) {
			pageResult = model.getModel();
		}
		String[] titles = { "数据代码", "数据名称","数据描述"};
		AjaxButton button1=new AjaxButton("查看                   ", "/datadicRest/datadic_item?id=");
		AjaxButton button2=new AjaxButton("修改                   ", "/datadicRest/to_edit_datadic?id=");
		AjaxButton button3=new AjaxButton("删除                   ", "/datadicRest/delete_datadic?id=");
		
		Button[] detailButton = new Button[] { button1,button2, button3};
		String pageUrl = "/datadic/index";
		pageUrl = UrlUtil.appendUrl(pageUrl, "name", vo.getName());
		pageUrl = UrlUtil.appendUrl(pageUrl, "code", vo.getCode());
		pageUrl = UrlUtil.appendUrl(pageUrl, "showPage", "");
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, pageUrl);
		paginationInfo.setBuildPagingNavigation(true);
		// paginationInfo.setFirstRenderColumnIndex(1);
		paginationInfo.setMoreButtons(detailButton);
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("vo", vo);

		BaseRestResult.refresh();
		return "/datadic/index";
	}

	
}
